The `new` command always expects a non-existing path. The `init` command
always expects an existing path. Therefore, it makes sense to hint to
use `init` if the pre-condition to `new` is not satisfied.
Fixes <https://github.com/rust-lang/cargo/issues/4366>
pub fn new(opts: NewOptions, config: &Config) -> CargoResult<()> {
let path = config.cwd().join(opts.path);
if fs::metadata(&path).is_ok() {
- bail!("destination `{}` already exists",
- path.display())
+ bail!("destination `{}` already exists\n\n\
+ Use `cargo init` to initialize the directory\
+ ", path.display()
+ )
}
if opts.lib && opts.bin {
- bail!("can't specify both lib and binary outputs");
+ bail!("can't specify both lib and binary outputs")
}
let name = get_name(&path, &opts, config)?;
fs::create_dir(&dst).unwrap();
assert_that(cargo_process("new").arg("foo"),
execs().with_status(101)
- .with_stderr(format!("[ERROR] destination `{}` already exists\n",
+ .with_stderr(format!("[ERROR] destination `{}` already exists\n\n\
+ Use `cargo init` to initialize the directory",
dst.display())));
}